/**
 * Created by adnimistrator on 2015/6/23.
 */
define("theme", function () {
    return theme =avalon.define ({
        $id:"theme",
        url:"./package/theme/theme.html",

        ready : function () {
//            alert(1);
            var id="All";
            theme.GetClass(id);
        },

        List:[],
        //请求class
        GetClass: function (id) {
            $.call({
                type:"post",
                i:"CMS_GetArticleClass",
                data:{
                    ClassID:id
                },
                success:function (data) {
                    if( data.c === 200 ) {
//                        tip.on("栏目获取成功",1);
                        theme.List=data.d.List;
                    }
                    else{
                        tip.on(data.m,0);
                    }
                }
            })
        },

        onfocus:-1,
        getIndex:function (index) {
            theme.onfocus=index;
        },
        gresetIndex:function () {
            theme.onfocus=-1;
        },

        //删除
        DelClass: function (id) {
            $.call({
                type:"post",
                i:"GetArticleList",
                data:{
                    ClassID:id
                },
                success:function (data) {
                    if( data.c === 200 ) {
                        //没有文章时  才可以删除
                        tip.on(data.d.Total);
                        if(data.d.Total === 0) {
                            $.call({
                                type:"post",
                                i:"CMS_DelArticleClass",
                                data:{
                                    ClassID:id
                                },
                                success:function (data) {
                                    if( data.c === 200 ) {
                                        tip.on("删除一个栏目",1);
                                        var all="All";
                                        theme.GetClass(all);
                                    }
                                    else{
                                        tip.on(data.m,0);
                                    }
                                }
                            })
                        }
                        else {
                            tip.on("还有文章数没有删除",1);
                        }
                    }
                    else{
                        tip.on(data.m,0);
                    }
                }
            })

        },

        //修改和发布新的类型
        toAdd:function (id) {
            require(['modal','addClass'], function () {
                modal.url='./package/addClass/addClass.html';
                modal.getIn();
                addClass.ready(id);
                addClass.GetClassName();
            })

        }


    })
})
